using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;

namespace WoWAddonRefresh.Entities {
	/// <summary>
	/// Summary description for Addon.
	/// </summary>
	public class Addon {
        private string name;
        public string Name {
            get { return name; }
            set { name = value; }
        }

        private string description;
        public string Description {
            get { return description; }
            set { description = value; }
        }

        private string changes;
        public string Changes {
            get { return changes; }
            set { changes = value; }
        }
	
        private string nameLink;
        public string NameLink {
            get { return nameLink; }
            set { nameLink = value; }
        }

        private string downloadURL;
        public string DownloadURL {
            get { return downloadURL; }
            set { downloadURL = value; }
        }

        public bool IsNew {
            get { return UploadDate > LocalDate; }
        }

        private DateTime uploadDate;
        public DateTime UploadDate {
            get { return uploadDate; }
            set { uploadDate = value; }
        }

        private TocCollection tocs = new TocCollection();
        public TocCollection Tocs {
            get { return tocs; }
            set { tocs = value; }
        }
	

        private int index;
        public int Index {
            get { return index; }
            set { index = value; }
        }

        private string fileName;
        public string FileName {
            get { return fileName; }
            set { fileName = value; }
        }
	
        private bool skip = false;
        public bool Skip {
            get { return skip; }
            set { skip = value; }
        }

        private DateTime localDate;
        public DateTime LocalDate {
            get { return localDate; }
            set { localDate = value; }
        }

        private bool addonChecked = false;
        public bool AddonChecked {
            get { return addonChecked; }
            set { addonChecked = value; }
        }
	}

    public class AddonCollection : BindingList<Addon> {

        public int CheckedAddonCount {
            get {
               int result = 0;
               foreach(Addon addon in this) {
                   if (addon.AddonChecked) result++;
               }
               return result;
            }
        }

        public AddonCollection CheckedAddons {
            get {
                AddonCollection addons = new AddonCollection();
                foreach (Addon addon in this) {
                    if (addon.AddonChecked) addons.Add(addon);
                }
                return addons;
            }
        }

        public Addon GetByNameLink(string nameLink) {
            foreach (Addon addon in this) {
                if (addon.NameLink == nameLink) return addon;
            }
            return null;
        }

        public Addon GetByIndex(int index) {
            foreach (Addon addon in this) {
                if (addon.Index == index) return addon;
            }
            return null;
        }

        public Addon GetByFileName(string fileName) {
            foreach (Addon addon in this) {
                if (addon.FileName == fileName) return addon;
            }
            return null;
        }

        public int GetIndexByFileName(string fileName) {
            foreach (Addon addon in this) {
                if (addon.FileName == fileName) return addon.Index;
            }
            return -1;
        }
        
        public int TocsCount {
            get {
                int result = 0;
                foreach (Addon addon in this) {
                    if (addon.Tocs != null) result += addon.Tocs.Count;
                }
                return result;
            }
        }
        
    } 
}
